/*Copyright ©2015 TommyLemon(https://github.com/TommyLemon)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

package soft.hb.activity;

import android.Manifest;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.mylhyl.acp.Acp;
import com.mylhyl.acp.AcpListener;
import com.mylhyl.acp.AcpOptions;

import java.util.List;

import soft.hb.R;
import zuo.biao.library.base.BaseActivity;
import zuo.biao.library.interfaces.OnHttpResponseListener;

/**首页
 * @author yuanweiwei
 */
public class IndexActivity extends BaseActivity implements OnClickListener, OnHttpResponseListener {
	public static final String TAG = "IndexActivity";

	/**获取启动LoginActivity的intent
	 * @param context
	 * @return
	 */
	public static Intent createIntent(Context context) {
		return new Intent(context, IndexActivity.class);
	}


	@Override
	public Activity getActivity() {
		return this; //必须return this;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.index_activity);
		intent = getIntent();

		//功能归类分区方法，必须调用<<<<<<<<<<
		initView();
		initData();
		initEvent();
		//功能归类分区方法，必须调用>>>>>>>>>>

	}


	//UI显示区(操作UI，但不存在数据获取或处理代码，也不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

	private LinearLayout layLoginBackground;

	@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
	@Override
	public void initView() {//必须调用
		layLoginBackground = findView(R.id.lay_login_background);
		showBlurBackground(layLoginBackground);
		findView(R.id.lay_mobile_apparatus).setOnClickListener(this);
		findView(R.id.lay_apparatus).setOnClickListener(this);
		findViewById(R.id.lay_survey_record).setOnClickListener(onClickListener);
		findViewById(R.id.lay_exhaust_detection).setOnClickListener(onClickListener);
		findViewById(R.id.lay_emission_exceeding_standard).setOnClickListener(onClickListener);
		findViewById(R.id.card_survey_record1).setOnClickListener(onClickListener);
	}




	//UI显示区(操作UI，但不存在数据获取或处理代码，也不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>










	//Data数据区(存在数据获取或处理代码，但不存在事件监听代码)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


	@Override
	public void initData() {//必须调用


	}

	//Data数据区(存在数据获取或处理代码，但不存在事件监听代码)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>








	//Event事件区(只要存在事件监听代码就是)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

	@Override
	public void initEvent() {//必须调用
	}




	//系统自带监听方法<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.lay_mobile_apparatus:
			Acp.getInstance(this).request(new AcpOptions.Builder()
							.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
									, Manifest.permission.READ_PHONE_STATE
									, Manifest.permission.CAMERA)
							.build(),
					new AcpListener() {
						@Override
						public void onGranted() {
							//检查（勘验）
							View dialogView = LayoutInflater.from(IndexActivity.this).inflate(R.layout.index_dialog,null);
							dialog(dialogView,R.style.Theme_Light_Dialog,R.style.dialogStyle);
							dialogView.findViewById(R.id.lay_survey_record).setOnClickListener(onClickListener);
							dialogView.findViewById(R.id.lay_exhaust_detection).setOnClickListener(onClickListener);
							dialogView.findViewById(R.id.lay_emission_exceeding_standard).setOnClickListener(onClickListener);
							dialogView.findViewById(R.id.card_survey_record1).setOnClickListener(onClickListener);

						}
						@Override
						public void onDenied(List<String> permissions) {
							showShortToast("请打开权限！");
						}
					});
//			final Dialog dialog = new Dialog(this, R.style.Theme_Light_Dialog);
//
//			//获得dialog的window窗口
//			Window window = dialog.getWindow();
//			//设置dialog在屏幕底部
//			window.setGravity(Gravity.BOTTOM);
//			//设置dialog弹出时的动画效果，从屏幕底部向上弹出
//			window.setWindowAnimations(R.style.dialogStyle);
//			window.getDecorView().setPadding(0, 0, 0, 0);
//			//获得window窗口的属性
//			android.view.WindowManager.LayoutParams lp = window.getAttributes();
//			//设置窗口宽度为充满全屏
//			lp.width = WindowManager.LayoutParams.MATCH_PARENT;
//			//设置窗口高度为包裹内容
//			lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
//			//将设置好的属性set回去
//			window.setAttributes(lp);
//			//将自定义布局加载到dialog上
//			dialog.setContentView(dialogView);
//			dialogView.findViewById(R.id.lay_survey_record).setOnClickListener(onClickListener);
//			dialogView.findViewById(R.id.lay_exhaust_detection).setOnClickListener(onClickListener);
//			dialogView.findViewById(R.id.lay_emission_exceeding_standard).setOnClickListener(onClickListener);
//			dialog.show();

			break;
			case R.id.lay_apparatus:
				//非道路移动器械
				View dialogView = LayoutInflater.from(this).inflate(R.layout.index_apparatus_dialog,null);
				dialog(dialogView,R.style.Theme_Light_Dialog,R.style.dialogStyle);
				dialogView.findViewById(R.id.lay_apparatus_task).setOnClickListener(onClickListener);

				break;
		}
	}




	//类相关监听<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

	private static final int REQUEST_TO_BOTTOM_MENU = 1;
	private static final int REQUEST_TO_EDIT_TEXT_INFO = 2;

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode != RESULT_OK) {
			return;
		}
		switch (requestCode) {
		case REQUEST_TO_BOTTOM_MENU:

			break;
		case REQUEST_TO_EDIT_TEXT_INFO:

			break;
		}
	}


	@Override
	public void finish() {
		super.finish();

	}

	@Override
	public void onHttpResponse(int requestCode, String resultJson, Exception e) {

	}


	//类相关监听>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	//系统自带监听方法>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


	//Event事件区(只要存在事件监听代码就是)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

	private OnClickListener onClickListener = new OnClickListener() {
		@Override
		public void onClick(final View v) {
			Acp.getInstance(IndexActivity.this).request(new AcpOptions.Builder()
							.setPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE
									, Manifest.permission.READ_PHONE_STATE
									, Manifest.permission.CAMERA)
							.build(),
					new AcpListener() {
						@Override
						public void onGranted() {
							switch (v.getId()) {
								case R.id.lay_survey_record:

									startActivity(SurveyRecordActivity.createIntent(IndexActivity.this));
									break;
								case R.id.lay_exhaust_detection:
									startActivity(DischargeActivity.createIntent(IndexActivity.this));
									break;
								case R.id.lay_emission_exceeding_standard:
									startActivity(ExhaustCheckActivity.createIntent(IndexActivity.this));
									break;
								case R.id.lay_apparatus_task:
									startActivity(PendingTaskActivity.createIntent(IndexActivity.this));
									break;
								case R.id.card_survey_record1:
									startActivity(CommSurveyRecordActivity.createIntent(IndexActivity.this));
									break;
							}
						}
						@Override
						public void onDenied(List<String> permissions) {
							showShortToast("请打开权限！");
						}
					});


		}
	};


}